﻿<%@ Page Language="C#" %>
<% 
    int changeState = Int16.Parse(Request["changeState"]);
    if (changeState == 1)
    {
        int index = Int16.Parse(Request["index"]);
        int newQuantity = Int16.Parse(Request["newQuantity"]);
        DTO.GioHangDto GioHang = (DTO.GioHangDto)Session["GioHang"];
        DTO.SanPhamDto sanphamTemp = BUS.SanPhamBus.LaySanPhamTheoID(GioHang.lstHang[index].ID);
        if (newQuantity > sanphamTemp.SoLuongCon)
            GioHang.lstHang[index].SoLuong = sanphamTemp.SoLuongCon;
        else
            GioHang.lstHang[index].SoLuong = newQuantity;
        Response.Write("<table width='100%' border='0' align='center' cellpadding='4' cellspacing='0'><tr><td class='table_header'>Giỏ hàng</td></tr><tr><td><br /><table width='95%' border='1' align='center' cellpadding='4' cellspacing='0' id='table_GioHang'><tr><td class='giohang_Header'>STT</td><td class='giohang_Header'>Tên sản phẩm</td><td class='giohang_Header'>Số lượng</td><td class='giohang_Header'>Đơn giá (ngàn)</td><td class='giohang_Header'>Khuyến mãi</td><td class='giohang_Header'>Giảm giá</td><td class='giohang_Header'>Thành tiền (ngàn)</td><td class='giohang_Header'>Xóa</td></tr>");
        double ThanhTien = 0;
        double TongThanhTien = 0;
        int j;
        for (int i = 0; i < GioHang.lstHang.Count; i++)
        {
            j = i + 1;
            ThanhTien = GioHang.lstHang[i].SoLuong * (GioHang.lstHang[i].DonGia - GioHang.lstHang[i].DonGia * GioHang.lstHang[i].RateGiamGia / 100 - GioHang.lstHang[i].DonGia * GioHang.lstHang[i].RateKhuyenMai / 100);
            TongThanhTien += ThanhTien;
            Response.Write("<tr><td>" + j + "</td><td><a href='Details.aspx?itemID=" + GioHang.lstHang[i].ID + "'><img class='hangTrongGio' src='" + GioHang.lstHang[i].UrlHinh + "' alt='' border='0'/></a><div style='padding-top:20px'><a class='linkStyle' href='Details.aspx?itemID=" + GioHang.lstHang[i].ID + "'>" + GioHang.lstHang[i].TenSanPham + "</a></div></td><td><input type='text' size='2' ID='txtSoLuong" + i + "' value='" + GioHang.lstHang[i].SoLuong + "' Width='30px' onKeyUp='changeQuantity(" + i + ");'/></td><td>" + GioHang.lstHang[i].DonGia + "</td><td class='validMessage'>" + GioHang.lstHang[i].RateKhuyenMai + "%</td><td class='validMessage'>" + GioHang.lstHang[i].RateGiamGia + "%</td><td>" + ThanhTien + "</td><td><img src='images/cancel_48.png' width='20' height='20' alt='' onclick='delProduct(" + i + ");' /></td></tr>");
        }
        GioHang.ThanhTien = TongThanhTien;
        Response.Write("<tr><td colspan='4' class='totalCostText'>Tổng thành tiền:</td><td class='totalCost' colspan='3'>" + GioHang.ThanhTien + "</td><td></td></tr>");
        Session["GioHang"] = GioHang;
    }
%>